<%@page import="cn.egame.interfaces.gc.GameInfo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="cn.egame.common.model.PageData"%>
<%@page import="java.util.*"%>
<%@page import="cn.egame.interfaces.pu.AppParameter"%>
<%@page import="cn.egame.interfaces.gc.GameInfo"%>  
<%@page import="cn.egame.interfaces.gc.GameTagLinkInfo"%> 
<%@page import="com.egame.manage.biz.server.pu.*"%> 
<%@page import="com.egame.manage.biz.utils.*"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/common.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link type="text/css" rel="stylesheet" href="<%=request.getContextPath() %>/css/main.css"  />
<script type="text/javascript">
function formSubmit(){	
	var urlString = "<%=request.getContextPath() + "/store/app/topic/list.do" %>";
	window.location.href=urlString;
}

function cancel(){
	var topicId = $("#topicId").attr("value");
	var urlString = "<%=request.getContextPath() + "/store/app/topic/delete/add.do?topic=" %>" + topicId;
	window.location.href=urlString;
}

function getOptionValueList(selectId){
	var options = document.getElementById(selectId);
	var result = new Array();
	for(var i=0;i<options.length;i++){
		if(options[i].selected == true){
			result.push(options[i].value);
		}
	}
	return result;
}

function getOptionValue(selectName){
	var select = document.getElementById(selectName);
	if(select == null)return null;
	var options = select.options;
	if(options == null)return null;
	var optionIndex = select.selectedIndex;
	if(optionIndex == null)return null;
	return options[optionIndex].value;
}

function getOptionText(selectName){
	var select = document.getElementById(selectName);
	if(select == null)return null;
	var options = select.options;
	if(options == null)return null;
	var optionIndex = select.selectedIndex;
	if(optionIndex == null)return null;
	return options[optionIndex].text;
}

function setOptionText(selectName,text){
	var select = document.getElementById(selectName);
	if(select == null)return null;
	var options = select.options;
	if(options == null)return null;
	var optionIndex = select.selectedIndex;
	if(optionIndex == null)return null;
	options[optionIndex].text = text;
}

function removeOption(selectName){
	var select = document.getElementById(selectName);
	if(select == null)return null;
	var options = select.options;
	if(options == null)return null;
	var optionIndex = select.selectedIndex;
	if(optionIndex == null)return null;
	options.remove(optionIndex);
}

function addOption(selectName,value,text){
	var select = document.getElementById(selectName);
	if(select == null)return null;
	var options = select.options;
	options.add(new Option(text,value));		
	options[options.length-1].selected = "selected";
}

function moveOption(fromId,toId){
	var options = document.getElementById(fromId);
	var toOptions = document.getElementById(toId);
	for(var i=0;i<options.length;i++){
		if(options[i].selected == true){
			toOptions.add(new Option(options[i].text,options[i].value));
			options.remove(i);
			--i;
		}
	}
}

function moveToOption(fromId,toId){
	var options = document.getElementById(fromId);
	var toOptions = document.getElementById(toId);
	for(var i=0;i<options.length;i++){
		if(options[i].selected == true){
			toOptions.options.add(new Option(options[i].text,options[i].value),0);
			options.remove(i);
			--i;
		}
	}
}

	function addRecommendGame(url){
		var value = getOptionValueList("gameList");
		if(value==null || value==""){
			alert("请选择要添加的游戏");
			return;
		}
		var sortSel = $("#sortSelect").attr("value");
		document.getElementById("gid").value = value;
		document.getElementById("myform").action = '<%=request.getContextPath() %>' + url +"?select="+sortSel;
		document.getElementById("myform").submit();
	}
	function deleteRecommendGame(url){
		var value = getOptionValueList("recommendList");
		if(value==null || value==""){
			alert("请选择要移除的游戏");
			return;
		}
		var sortSel = $("#sortSelect").attr("value");
		document.getElementById("gid").value = value;
		document.getElementById("myform").action = '<%=request.getContextPath() %>'  + url +"?select="+sortSel;
		document.getElementById("myform").submit();
	}
	function moveRecommendGame(url){
		var value = getOptionValueList("recommendList");		
		if(value==null || value==""){
			alert("请选择要移动的游戏");
			return;
		}else{
			var values = value.toString().split(",");
			if(values.length>1){
				alert("只能选择一个要移动的游戏");
				return;
			}			
		}
		var sortSel = $("#sortSelect").attr("value");
		document.getElementById("gid").value = value;
		document.getElementById("myform").action = '<%=request.getContextPath() %>' + url +"?select="+sortSel;	
		document.getElementById("myform").submit();
	}	
</script>
<title>推荐列表</title>
</head>
<body>
	
<form id="myform" action="<%=request.getContextPath() + "/store/app/topic/sort.do" %>" method="post">
<input type="hidden" name=gid id=gid>
<% 	
	String gameName = "";
	if(request.getAttribute("gameName")!=null){
		gameName = (String)request.getAttribute("gameName");
	}
	String recommendName = "";
	if(request.getAttribute("recommendName")!=null){
		recommendName = (String)request.getAttribute("recommendName");
	}	
	
	int topicId = 0;
	if(request.getAttribute("topicId")!=null){
		topicId = (Integer)request.getAttribute("topicId");
	}	
%>

<div class="mt10 pt10 clearfix">
<table>
	<tr>
		<td>
			<table>				
				<tr>
					<td width=35% align=center><p style="font-size: 16px;margin-bottom: 20px;font-weight: bold;">软件列表</p></td>
					<td></td>
					<td width=30% align=center><p style="font-size: 16px;margin-bottom: 20px;font-weight: bold;">已添加软件</p></td>
					<td></td>					
				</tr>	
				<tr>
					<td colspan=2>
					<input type="hidden" id="topicId" name="topicId" value="<%=topicId %>">
						软件ID/软件名称:<input type=text name="gname" value="<%=gameName %>">
						<input type="submit" value="查询" class="btn3">
					</td>
					<td colspan=2>
					<input type="hidden" id="sortSelect" name="sortSelect" value="<%=topicId %>">
						软件ID/软件名称:<input type=text name="recommendname"  value="<%=recommendName %>">
						<input type=submit value="查询" class="btn3">
					</td>					
				</tr>			
				<tr>
					<td>
						<select name="gameList" id="gameList" size="20" style="width:240px;" multiple="multiple">
							<%
								if(request.getAttribute("gameList")!=null){
									List<GameInfo> list = (List<GameInfo>)request.getAttribute("gameList");
									for(GameInfo bean:list){
										%>
											<option id="<%=bean.getGId() %>" value=<%=bean.getGId() %>>												
												[<%=bean.getGId() %>]--
												<%=bean.getGameName() %>--
												(<%=bean.getOsCode() %>)
											</option>
										<%
									}
								}
								
							%>
						</select>
					</td>
					<td>
						<input type=button value="添加 >" class="btn3"  onclick="addRecommendGame('/store/app/topic/sort/increase.do')"> <br/>
						<input type="button" class="btn3" onclick="deleteRecommendGame('/store/app/topic/sort/decrease.do')" value="< 移除"><br/>
					</td>
					
					<td>
						<select name="recommendList" id="recommendList" size="20" style="width:240px;"  multiple="multiple">
							<%
								if(request.getAttribute("recommendList")!=null){
									List<GameInfo> list = (List<GameInfo>)request.getAttribute("recommendList");
									for(GameInfo bean:list){
										%>
											<option id="<%=bean.getGId() %>" value=<%=bean.getGId() %>>												
												[<%=bean.getGId() %>]--
												<%=bean.getGameName() %>--
												(<%=ParameterServiceImpl.getInstance().getParameterNameById(0,0L,ConstVar.APP_OS,""+bean.getOsCode()) %>)
											</option>
										<%
									}
								}
								
							%>
						</select>
					</td>
					<td>
						<input type="button" class="btn3" onclick="moveRecommendGame('/store/app/soft/sort/upper.do')" value="上移"><p>
						<input type="button" class="btn3" onclick="moveRecommendGame('/store/app/soft/sort/lower.do')" value="下移"><p>
						<input type="button" class="btn3" onclick="moveRecommendGame('/store/app/soft/sort/top.do')" value="置顶"><p>
						<input type="button" class="btn3" onclick="moveRecommendGame('/store/app/soft/sort/down.do')" value="置底"><p>						
						
					</td>					
				</tr>
				<tr>
				<td colspan=2>
					<input type=button onclick="formSubmit()" class="btn3" value="确认" style="margin-top: 50px;margin-left: 400px;">
					<input type=button onclick="cancel()" class="btn3" value="取消">
				</td>
			</tr>
			</table>
		</td>
	</tr>
</table>
</div>
</div>
</form>
</body>
</html>